﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Charting;
using BSCMFF.Core.BusinessLayer;

namespace BSCMFF.Web.UserControls.Evaluation
{
    /// <summary>
    /// Bonus sigmoid.
    /// </summary>
    /// <remarks></remarks>
    public partial class BonusSigmoid : System.Web.UI.UserControl
    {
        /// <summary>
        /// Gets or sets the public value A.
        /// </summary>
        /// <value>The public value A.</value>
        /// <remarks></remarks>
        public double PublicValueA
        {
            get
            {
                return (double)RadNumericTextBoxA.Value;
            }
            set
            {
                RadNumericTextBoxA.Value = value;
            }
        }

        /// <summary>
        /// Gets or sets the public value B.
        /// </summary>
        /// <value>The public value B.</value>
        /// <remarks></remarks>
        public double PublicValueB
        {
            get
            {
                return (double)RadNumericTextBoxB.Value;
            }
            set
            {
                RadNumericTextBoxB.Value = value;
            }
        }
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks></remarks>
        protected void Page_Load(object sender, EventArgs e)
        {            
            if (((CheckBox)this.Parent.FindControl("CheckBoxReward")).Checked == false)
            {
                return;
            }
            if (((CheckBox)this.Parent.FindControl("CheckBoxPKPIs")).Checked == false)
            {
                this.Visible = false;
            }
            else
            {
                this.Visible = true;
            }

            if (!IsPostBack)
            {
                RadChart1.RemoveAllSeries();
            }

            if (RadChart1.Series.Count > 0)
            {
                RadButtonClear.Visible = true;
            }
            else
            {
                RadButtonClear.Visible = false;
            }

            if (RadChart1.Series.Count > 3)
            {
                RadButtonTry.Visible = false;
            }
            else
            {
                RadButtonTry.Visible = true;
            }
            
            ChartSeries chs = new ChartSeries();
            chs.Type = ChartSeriesType.Spline;

            chs.Appearance.LabelAppearance.Visible = false;

            List<double> data = new List<double>();
            for (int i = 0; i < 100; ++i)
            {
                double vysledok = SigmoidHelper.Sigmoid(i, (double)RadNumericTextBoxA.Value, (double)RadNumericTextBoxB.Value);
                
                ChartSeriesItem chi = new ChartSeriesItem();
                chi.YValue = vysledok;
                chs.Items.Add(chi);
            }
            RadChart1.Series.Add(chs);
            chs.PlotArea.XAxis.LabelStep = 5;
            chs.PlotArea.XAxis.MinValue = 0;
            chs.PlotArea.XAxis.AxisLabel.TextBlock.Text = "Performance";
            chs.Name = RadNumericTextBoxA.Value.ToString() + " - " + RadNumericTextBoxB.Value.ToString();
            chs.PlotArea.XAxis.Appearance.LabelAppearance.Visible = true;
            
        }
        
        /// <summary>
        /// Handles the Click event of the RadButtonClear control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks></remarks>
        protected void RadButtonClear_Click(object sender, EventArgs e)
        {
            RadChart1.RemoveAllSeries();
        }
    }
}